home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / rxdoscmd.zip / RXDOSREN.ASM < prev    next >
Assembly Source File  |  1993-06-07  |  14KB  |  310 lines

  1.         TITLE   'Ren - RxDOS Command Shell Rename'
  2.         PAGE 59, 132
  3.         .LALL
  4.  
  5.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  6.         ;  RxDOS Command Shell Rename                                   ;
  7.         ;...............................................................;
  8.  
  9.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  10.         ;  Real Time Dos                                                ;
  11.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  12.         ;                                                               ;
  13.         ;  This material  was created as a published version  of a DOS  ;
  14.         ;  equivalent product.   This program  logically  functions in  ;
  15.         ;  the same way as  MSDOS functions and it  is  internal  data  ;
  16.         ;  structure compliant with MSDOS 5.0                           ;
  17.         ;                                                               ;
  18.         ;  This product is distributed  AS IS and contains no warranty  ;
  19.         ;  whatsoever,   including  warranty  of   merchantability  or  ;
  20.         ;  fitness for a particular purpose.                            ;
  21.         ;                                                               ;
  22.         ;                                                               ;
  23.         ;  (c) Copyright 1990, 1992. Api Software and Mike Podanoffsky  ;
  24.         ;      All Rights Reserved Worldwide.                           ;
  25.         ;                                                               ;
  26.         ;  This product is protected under copyright laws and  may not  ;
  27.         ;  be reproduced  in whole  or in part, in any form  or media,  ;
  28.         ;  included but not limited to source listing, facimilie, data  ;
  29.         ;  transmission, cd-rom, or  floppy disk without the expressed  ;
  30.         ;  written consent of the author.                               ;
  31.         ;                                                               ;
  32.         ;  Licence for distribution in commercial use:                  ;
  33.         ;                                                               ;
  34.         ;  Api Software                                                 ;
  35.         ;  12 South Walker Street                                       ;
  36.         ;  Lowell,  MA   01851                                          ;
  37.         ;  508/ 454-4961.                                               ;
  38.         ;                                                               ;
  39.         ;...............................................................;
  40.  
  41.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  42.         ;  RxDOS Command Shell                                          ;
  43.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  44.         ;                                                               ;
  45.         ;  Programmer's Notes:                                          ;
  46.         ;                                                               ;
  47.         ;  Command Shell consists of  two parts bound  together into a  ;
  48.         ;  single executable load.  There  exists  a  single  resident  ;
  49.         ;  command shell which is accessible by an Int 2Eh.             ;
  50.         ;                                                               ;
  51.         ;...............................................................;
  52.  
  53.         include rxdosmac.asm
  54.         include rxdosdef.asm
  55.         include rxdoscin.asm
  56.  
  57.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  58.         ;  RxDOS Command Shell                                          ;
  59.         ;...............................................................;
  60.  
  61. RxDOSCMD SEGMENT PUBLIC 'CODE'
  62.          assume cs:RxDOSCMD, ds:RxDOSCMD, es:RxDOSCMD, ss:RxDOSCMD
  63.  
  64.         public _Rename
  65.  
  66.         extrn CmndError_FileAlreadyExists               : near
  67.         extrn DisplayErrorMessage                       : near
  68.         extrn DisplayLine                               : near
  69.         extrn PreProcessCmndLine                        : near
  70.         extrn RxDOS_DTA                                 : near
  71.         extrn _CopyString                               : near
  72.         extrn _lowerCase                                : near
  73.         extrn _splitpath                                : near
  74.         extrn _makePath                                 : near
  75.  
  76.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  77.         ;  Rename filenameA filenameB                                   ;
  78.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  79.         ;                                                               ;
  80.         ;  Usage:                                                       ;
  81.         ;   ss:di  Arg Array                                            ;
  82.         ;   ax     Number of arguments in array                         ;
  83.         ;...............................................................;
  84.  
  85. _Rename:
  86.  
  87.         Entry
  88.         def _filesRenamed                               ; how many renamed
  89.         def __argarray, di                              ; args array
  90.         defbytes _renamedFileName, 15
  91.         defbytes _expandedname, sizeExpandedName
  92.  
  93.         mov cx, 2                                       ; must have two arguments
  94.         mov dx, cx                                      ; must have two arguments
  95.         xor bx, bx
  96.         call PreProcessCmndLine                         ; make sure args are ok
  97.         ifc _renameError                                ; if error -->
  98.  
  99. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  100. ;  make sure second arg contains no drive or path info
  101. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  102.  
  103.         mov di, word ptr [ __argarray ][ bp ]
  104.         mov si, word ptr [ di + 2 ]                     ; second argument
  105.         lea di, offset [ _expandedname ][ bp ]          ; test expansion
  106.         call _splitpath                                 ; make sure second arg contains no drive, path
  107.  
  108.         cmp byte ptr [ _expandedname. expDrive ][ bp ], 0
  109.         ifnz _renameError                               ; if error -->
  110.         cmp byte ptr [ _expandedname. expPath  ][ bp ], 0
  111.         ifnz _renameError                               ; if error -->
  112.  
  113. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  114. ;  test for simple (no wild card case)
  115. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  116.  
  117.         mov di, word ptr [ __argarray ][ bp ]
  118.         mov si, word ptr [ di ]                         ; first arg
  119.         call _scanWildCharacters                        ; does filename contain wild characters 
  120.         jz _rename_12                                   ; yes -->
  121.  
  122.         mov si, word ptr [ di + 2 ]                     ; second arg
  123.         call _scanWildCharacters                        ; does filename contain wild characters 
  124.         jz _rename_12                                   ; yes -->
  125.  
  126.         mov dx, word ptr [ di ]                         ; first arg
  127.         mov di, word ptr [ di + 2 ]                     ; second arg
  128.         Int21 RenameFile                                ; rename file
  129.         jc _renameError                                 ; if error -->
  130.  
  131.         Return
  132.  
  133. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  134. ;  split path name into [drive:] [path] [filename]
  135. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  136.  
  137. _rename_12:
  138.         mov cx, sizefnName
  139.         lea si, offset [ _expandedname. expFilename ][ bp ]
  140.         call _expandWildCharacters
  141.  
  142.         mov cx, sizefnExtension+1
  143.         lea si, offset [ _expandedname. expExtension ][ bp ]
  144.         call _expandWildCharacters
  145.  
  146. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  147. ;  determine if files to rename
  148. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  149.         storarg _filesRenamed, 0000                     ; none renamed so far
  150.  
  151.         mov di, word ptr [ __argarray ][ bp ]
  152.         mov dx, word ptr [ di ]                         ; first arg
  153.         Int21 FindFirstFile                             ; locate file with name
  154.         jc _rename_36                                   ; if no more -->
  155.  
  156. _rename_18:
  157.         mov si, offset [ RxDOS_DTA. findFileName ]
  158.         lea bx, offset [ _expandedname. expFilename ][ bp ]
  159.         lea di, offset [ _renamedFileName   ][ bp ]
  160.         call _renameCopy
  161.  
  162.         lea bx, offset [ _expandedname. expExtension ][ bp ]
  163.         cmp byte ptr [ bx ], 0
  164.         jz _rename_22
  165.  
  166.         push di
  167.         mov al, '.'
  168.         mov cx, (sizefnName+1)
  169.         mov di, offset [ RxDOS_DTA. findFileName ]
  170.         repnz scasb                                     ; locate '.'
  171.         mov si, di
  172.         pop di
  173.         jnz _rename_22
  174.  
  175.         stosb                                           ; add period if one located
  176.         inc bx                                          ; skip expansion period.
  177.         call _renameCopy
  178.  
  179. _rename_22:
  180.         mov dx, offset [ RxDOS_DTA. findFileName ]
  181.         lea di, offset [ _renamedFileName   ][ bp ]
  182.         Int21 RenameFile                                ; rename file
  183.         jc _renameError                                 ; if error -->
  184.  
  185.         inc word ptr [ _filesRenamed ][ bp ]            ; number renamed
  186.         Int21 FindNextFile                              ; more files to rename ?
  187.         jnc _rename_18                                  ; if more -->
  188.  
  189. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  190. ;  return
  191. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  192.  
  193. _rename_36:
  194.         cmp word ptr [ _filesRenamed ][ bp ], 0000      ; any files renamed ?
  195.         jz _renameError                                 ; if none -->
  196.         Return
  197.  
  198. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  199. ;  error in rename command
  200. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  201.  
  202. _renameError:
  203.         mov dx, offset CmndError_FileAlreadyExists
  204.         call DisplayErrorMessage
  205.         Return
  206.  
  207.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  208.         ;  Scan For Wild Characters                                     ;
  209.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  210.         ;                                                               ;
  211.         ;  Usage:                                                       ;
  212.         ;   ss:si  pointer to null terminated name                      ;
  213.         ;...............................................................;
  214.  
  215. _scanWildCharacters:
  216.  
  217.         push si
  218.  
  219. _scanWildCharacters_08:
  220.         lodsb
  221.         or al, al
  222.         jz _scanWildCharacters_16
  223.  
  224.         cmp al, '?'
  225.         jz _scanWildCharacters_18
  226.         cmp al, '*'
  227.         jz _scanWildCharacters_18
  228.         jmp _scanWildCharacters_08
  229.  
  230. _scanWildCharacters_16:
  231.         cmp al, '?'
  232.         
  233. _scanWildCharacters_18:
  234.         pop si
  235.         ret
  236.  
  237.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  238.         ;  Expand Wild Characters                                       ;
  239.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  240.         ;                                                               ;
  241.         ;  Usage:                                                       ;
  242.         ;   ss:si  pointer to null terminated name                      ;
  243.         ;...............................................................;
  244.  
  245. _expandWildCharacters:
  246.  
  247.         lodsb
  248.         or al, al
  249.         jz _expandWildCharacters_10
  250.  
  251.         cmp al, '*'
  252.         jz _expandWildCharacters_12
  253.         loop _expandWildCharacters
  254.  
  255. _expandWildCharacters_10:
  256.         ret
  257.  
  258. _expandWildCharacters_12:
  259.         mov di, si
  260.         dec di
  261.         mov al, '?'
  262.         rep stosb                                       ; fill with ? ...
  263.  
  264.         xor ax, ax
  265.         stosb                                           ; add null terminator
  266.         ret
  267.  
  268.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  269.         ;  Create Renamed Name                                          ;
  270.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  271.         ;                                                               ;
  272.         ;  Usage:                                                       ;
  273.         ;   ss:si  current name of file from find                       ;
  274.         ;   ss:bx  wild character matching template                     ;
  275.         ;   ss:di  output name field                                    ;
  276.         ;...............................................................;
  277.  
  278. _renameCopy:
  279.  
  280.         mov al, byte ptr [ si ]
  281.         or al, al
  282.         jz _renameCopy_12
  283.         cmp al, '.'
  284.         jz _renameCopy_12
  285.  
  286.         mov al, byte ptr [ bx ]
  287.         or al, al
  288.         jz _renameCopy_12 
  289.         cmp al, '?'
  290.         jnz _renameCopy_08
  291.  
  292.         mov al, byte ptr [ si ]
  293.  
  294. _renameCopy_08:
  295.         mov byte ptr [ di ], al
  296.  
  297.         inc si
  298.         inc di
  299.         inc bx
  300.         jmp _renameCopy
  301.  
  302. _renameCopy_12:
  303.         mov byte ptr [ di ], 00
  304.         ret
  305.  
  306. RxDOSCMD                        ENDS
  307.                                 END
  308.  
  309.  
  310.